package kr.co.dayve.site.management.dao;

import kr.co.dayve.site.domain.CommunityBoard;
import kr.co.dayve.site.domain.PhotoBoard;
import kr.co.dayve.site.domain.Report;
import kr.co.dayve.site.domain.Vote;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;


public class PhotoBoardDaoImpl extends SqlMapClientDaoSupport implements PhotoBoardDao {
    public List getBoardListBySearchword(PhotoBoard board) {

        /**
         * Null 에러 방지용 공백 전환
         */
        if(board.getTitle() == null){
            board.setTitle("");
        }

        if(board.getWriter_id() == null){
            board.setWriter_id("");
        }

        if(board.getWriter_nick_name() == null){
            board.setWriter_nick_name("");
        }

        if(board.getContent() == null){
            board.setContent("");
        }

        return getSqlMapClientTemplate().queryForList("PBOARD.getBoardListBySearchword", board, board.getCurrentPage() * board.getPageSize(), board.getPageSize());
    }

    public List getBoardListByNo(PhotoBoard board){
        return getSqlMapClientTemplate().queryForList("PBOARD.getBoardListByNo", board, board.getCurrentPage() * board.getPageSize(), board.getPageSize());
    }

    public String getTotalCountBySearchword(PhotoBoard board) {
        return (String)getSqlMapClientTemplate().queryForObject("PBOARD.getTotalCountBySearchword", board);
    }

    public String getTotalCountByNo(PhotoBoard board) {
        return (String)getSqlMapClientTemplate().queryForObject("PBOARD.getTotalCountByNo", board);
    }

    public String writeBoard(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.writeBoard", board));
    }

    public String updateBoard(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.updateBoard", board));
    }

    public String deleteBoard(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.deleteBoard", board));
    }

    public PhotoBoard getBoardByNo(String photo_board_no){
        return (PhotoBoard)getSqlMapClientTemplate().queryForObject("PBOARD.getBoardByNo", photo_board_no);
    }

    public String updateReplyCount(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.updateReplyCount", board));
    }

    public String updateHitCount(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.updateHitCount", board));
    }

    public String updateVoteCount(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.updateVoteCount", board));
    }

    public String updateNegativeCount(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.updateNegativeCount", board));
    }

    public String updateReportCount(PhotoBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.updateReportCount", board));
    }

    public String checkDuplicateVote(Vote vote) {
        return (String)getSqlMapClientTemplate().queryForObject("PBOARD.checkDuplicateVote", vote);
    }

    public String insertVoterToList(Vote vote) {
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.insertVoterToList", vote));
    }

    public String photoBoardReport(Report report) {
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.photoBoardReport", report));
    }

    public String checkDuplicateReport(Report report) {
        return (String)getSqlMapClientTemplate().queryForObject("PBOARD.checkDuplicateReport", report);
    }

    public String updateBoardNotImage(PhotoBoard board) {
        return Integer.toString(getSqlMapClientTemplate().update("PBOARD.updateBoardNotImage", board));
    }
}
